package uy.com.tsi2G7.superbet.ui;

import java.math.BigDecimal;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

public abstract class AbstractBean {
	
	@ManagedProperty(value="#{panelMenuBean}")
	protected PanelMenuBean panelMenuBean;
	
	protected MenuDescriptor event;
	protected MenuDescriptor eventType;
	protected MarketsDescriptor market;
	protected MarketsResultDescriptor marketResult;
	protected BigDecimal amount=BigDecimal.ZERO;
	

	
	public String getEventName() {
		if(event==null)
			event=panelMenuBean.getCurrentSample();
		return event.getName();
	}

	public String getEventTypeName() {
		if(eventType==null)
			eventType=panelMenuBean.getCurrentGroup();
		return eventType.getName();
	}

	public String getMarketName() {
		if(market==null)
			market=panelMenuBean.getMarket();
		return market.getName();
	}

	public String getMarketResultName() {
		if(marketResult==null)
			marketResult=panelMenuBean.getMarketResult();
		return marketResult.getName();
	}
	
	public String getResultAmount() {
		if(marketResult==null)
			marketResult=panelMenuBean.getMarketResult();
		return marketResult.getAmount();
	}
	public PanelMenuBean getPanelMenuBean() {
		return panelMenuBean;
	}
	public void setPanelMenuBean(PanelMenuBean panelMenuBean) {
		this.panelMenuBean = panelMenuBean;
	}
	public void showErrorMessage(String message) {
		if (message == null || "".equals(message.trim())) {
			message = "Error desconocido. Contacte al administrador";
		}
		FacesContext.getCurrentInstance()
				.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
	}
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	

}
